import java.util.Arrays;

public class Solution80 {
    public int removeDuplicates(int[] nums) {
        int j=1,count=1;
        for (int i=1;i<nums.length;i++){
            if (nums[i]==nums[j-1] && count<=1 ||nums[i]!=nums[j-1]){
                if (nums[i]==nums[j-1]){
                    count++;
                }else{
                    count=1;
                }
                nums[j]=nums[i];
                j++;
            }
        }
        return j;
    }

    public static void main(String[] args) {
        int[] f=new int[]{1,1,1,2,2,3};
        System.out.println(new Solution80().removeDuplicates(f));
        System.out.println(Arrays.toString(f));
    }
}
